<template>
  <ul class="app-header-nav">
    <!-- {{$store.state.nav.newidnex}} -->
    <li class="home" @click="back()"><RouterLink to="/">首页</RouterLink></li>
    <li v-for="(item, index) in navname" :key="index">
      <a
        :class="{ actives: index === $store.state.nav.newidnex }"
        @click="tiao(index, item.id)"
        >{{ item.name }}</a
      >
      <div class="layer">
        <ul>
          <li v-for="it in item.children" :key="it.id">
            <router-link :to="'/reclassify?id=' + it.id">
              <img :src="it.picture" alt="" />
              <p>{{ it.name }}</p>
            </router-link>
          </li>
        </ul>
      </div>
    </li>
  </ul>
</template>

<script>
export default {
  data() {
    return {
      id: null,
      index: null,
    };
  },
  computed: {
    navname() {
      return this.$store.state.nav.navigation;
    },
  },
  methods: {
    tiao(index, id) {
      this.index = index;
      this.$store.commit("nav/addnumebr", index);
      this.$router.push("/cate?id=" + id);
    },

    back() {
      this.$store.commit("nav/addnumebr", "");
      this.$router.push("/");
    },
  },
};
</script>

<style scoped lang="scss">
@import "@/assets/css/color.scss";
.app-header-nav {
  width: 820px;
  display: flex;
  justify-content: space-around;
  padding-left: 40px;
  position: relative;
  z-index: 998;
  > li {
    margin-right: 40px;
    width: 38px;
    text-align: center;
    > a {
      font-size: 16px;
      line-height: 32px;
      height: 32px;
      display: inline-block;
    }
    &:hover {
      > a {
        color: #27ba9b;
        border-bottom: 1px solid #27ba9b;
      }
      > .layer {
        height: 132px;
        opacity: 1;
      }
    }
  }
}
.layer {
  width: 1240px;
  background-color: #fff;
  position: absolute;
  left: -200px;
  top: 56px;
  height: 0;
  overflow: hidden;
  opacity: 0;
  box-shadow: 0 0 5px #ccc;
  transition: all 0.2s 0.1s;
  z-index: 9991;
  ul {
    display: flex;
    flex-wrap: wrap;
    padding: 0 70px;
    align-items: center;
    height: 132px;

    li {
      width: 110px;
      text-align: center;
      img {
        width: 60px;
        height: 60px;
      }
      p {
        padding-top: 10px;
      }
      &:hover {
        p {
          color: #27ba9b;
        }
      }
    }
  }
}
.actives {
  border-bottom: 1px solid #27ba9b;
  color: #27ba9b;
}
</style>
